# -*- coding: UTF-8 -*-
"""
@Project : FastTortoiseDemo
@File    : .py
@IDE     : PyCharm
@Author  : xuan
@Date    : 2024/3/7 16:35
"""
from tortoise import Tortoise
from Config.setting import settings


async def init_db():
    """
    数据库DB初始化, 建立链接
    :return:
    """
    await Tortoise.init(
        db_url=settings.TORTOISE_ORM,
        modules={"models": ["Apps.user.user_models"]},
        # generate_schemas=True,
        # add_exception_handlers=True,
    )
    await Tortoise.generate_schemas()


async def close_db():
    """
    关闭DB链接
    :return:
    """
    await Tortoise.close_connections()
